package com.yanzhen.service;

import com.yanzhen.dao.IDeptDao;
import com.yanzhen.po.Dept;
import com.yanzhen.po.Node;
import com.yanzhen.util.TreeBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service("deptService")
public class IDeptServiceImpl implements IDeptService {
    @Autowired
    private IDeptDao iDeptDao;
    @Autowired
    private TreeBuilder treeBuilder;
//    查询所有
    @Override
    public List<Dept> queryDeptAll() {
        return iDeptDao.queryDeptAll();
    }
//      添加部门
    @Override
    public void addDept(Dept dept) {
        iDeptDao.addDept(dept);
    }

    @Override
    public Dept queryDeptByID(Integer id) {
        return iDeptDao.queryDeptByID(id);
    }

    @Override
    public void updateDept(Dept dept) {
        dept.setCreateTime(new Date());
        iDeptDao.updateDept(dept);
    }


    @Override
    public void deleteDeptById(Integer id) {
        iDeptDao.deleteDeptById(id);
    }

    @Override
    public List<Node> queryDeptTree() {
        List<Node> nodeList = iDeptDao.queryDeptTree();
//        封装树结构
        treeBuilder.buildTree(nodeList);
        return nodeList;
    }

}
